package com.cy.pj.modules.controller;

import com.cy.pj.common.vo.JsonResult;
import com.cy.pj.modules.entity.Shop;
import com.cy.pj.modules.service.IShopService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 商家信息Controller
 *
 * @author kiven
 * @date 2023-02-09
 */
@Controller
@RequestMapping("/shop")
public class ShopController
{
    private String prefix = "modules/shop";

    @Autowired
    private IShopService shopService;

    @RequiresPermissions("shop:view")
    @GetMapping()
    public String shop()
    {
        return prefix + "/shop";
    }

    /**
     * 查询商家信息列表
     */
    @RequiresPermissions("shop:list")
    @GetMapping("/list")
    @ResponseBody
    public JsonResult list(Shop shop, Integer pageCurrent)
    {
        return new JsonResult(shopService.selectShopList(shop,pageCurrent));
    }

    ///**
    // * 导出商家信息列表
    // */
    //@RequiresPermissions("pj:shop:export")
    //@PostMapping("/export")
    //@ResponseBody
    //public JsonResult export(Shop shop)
    //{
    //    List<Shop> list = shopService.selectShopList(shop);
    //    ExcelUtil<Shop> util = new ExcelUtil<Shop>(Shop.class);
    //    return util.exportExcel(list, "shop");
    //}

    /**
     * 新增商家信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商家信息
     */
    @RequiresPermissions("shop:add")
    @PostMapping("/add")
    @ResponseBody
    public JsonResult addSave(Shop shop)
    {
        return new JsonResult(shopService.insertShop(shop));
    }

    /**
     * 修改商家信息
     */
    @GetMapping("/edit")
    public String edit(Long id, ModelMap mmap)
    {

        Shop shop = shopService.selectShopById(id);
        mmap.put("shop", shop);
        return prefix + "/shop_edit";
    }

    @GetMapping("/id")
    @ResponseBody
    public JsonResult byId(Long  id){
        return new JsonResult(shopService.selectShopById(id));
    }

    /**
     * 修改保存商家信息
     */
    @RequiresPermissions("shop:update")
    @PostMapping("/edit")
    @ResponseBody
    public JsonResult editSave(Shop shop)
    {
        return new JsonResult(shopService.updateShop(shop));
    }

    /**
     * 删除商家信息
     */
    @RequiresPermissions("shop:remove")
    @PostMapping( "/remove")
    @ResponseBody
    public JsonResult remove(String ids)
    {
        return new JsonResult(shopService.deleteShopByIds(ids));
    }
}
